package com.athuiju.fenxiaoback.controller;


import com.athuiju.fenxiaoback.entity.Employee;
import com.athuiju.fenxiaoback.entity.UmsMemberReceiveAddress;
import com.athuiju.fenxiaoback.entity.WorkAbility;
import com.athuiju.fenxiaoback.entity.WorkPhilosophy;
import com.athuiju.fenxiaoback.entity.vo.EwwVo;
import com.athuiju.fenxiaoback.service.EmployeeService;
import com.athuiju.fenxiaoback.service.WorkAbilityService;
import com.athuiju.fenxiaoback.service.WorkPhilosophyService;
import com.athuiju.fenxiaoback.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zs
 * @since 2021-10-15
 */
@RestController
@RequestMapping("/fenxiaoback/employee")
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;
    @Autowired
    WorkAbilityService workAbilityService;

    @Autowired
    WorkPhilosophyService workPhilosophyService;
    /*
    @ApiOperation(value = "列表1")
    @GetMapping("list1")
    public R list1(HttpServletRequest request) {

        List<Employee> employeelist = employeeService.list(null);

        List<WorkPhilosophy> philosophylist = workPhilosophyService.list(null);

        List<WorkAbility> abilitylist = workAbilityService.list(null);



        List<EwwVo> voList=new ArrayList<>();
        HashMap<String,EwwVo> mapvoList=new HashMap<>();
        for (int i=0;i<employeelist.size();i++){
            for (int m=0;m<philosophylist.size();m++){
                for (int n=0;n<abilitylist.size();n++) {
                    if (employeelist.get(i).getPId().equals(philosophylist.get(m).getPid())
                    || employeelist.get(i).getPId().equals(abilitylist.get(n).getPid())
                    ){
                        EwwVo ewwVo=new EwwVo();

                        //employeelist.get(i).setPId(philosophylist.get(m).getPid());
                        ewwVo.setPid(employeelist.get(i).getPId());
                        ewwVo.setName(employeelist.get(i).getName());
                        ewwVo.setYear(philosophylist.get(m).getYear());
                        ewwVo.setQuarter(philosophylist.get(m).getQuarter());
                        ewwVo.setPtotal(philosophylist.get(m).getTotal());
                        ewwVo.setPpoint(philosophylist.get(m).getPoint());
                        ewwVo.setAtotal(abilitylist.get(n).getTotal());
                        ewwVo.setApoint(abilitylist.get(n).getPoint());
                        //ewwVo.setTotal(philosophylist.get(m).getPoint()
                        //        //+abilitylist.get(n).getPoint()
                        //);
                        //String key=""+employeelist.get(i).getPId()+employeelist.get(i).getName()+philosophylist.get(m).getYear()+philosophylist.get(m).getQuarter();
                        //voList.add(ewwVo);
                        //EwwVo mapewwVo = mapvoList.get(key);
                        //if (mapewwVo == null){
                        //
                        //}
                        voList.add(ewwVo);

                    }


                }
            }
        }
        return R.ok().put("data",voList);
    }


    @ApiOperation(value = "列表2")
    @GetMapping("list2")
    public R list2(HttpServletRequest request) {


        List<Employee> employeelist = employeeService.list(null);

        List<WorkPhilosophy> philosophylist = workPhilosophyService.list(null);

        List<WorkAbility> abilitylist = workAbilityService.list(null);


        List<EwwVo> philosophyvoList=new ArrayList<>();
        List<EwwVo> abilityvoList=new ArrayList<>();
        for (int i=0;i<employeelist.size();i++){
            for (int m=0;m<philosophylist.size();m++){
                if (employeelist.get(i).getPId().equals(philosophylist.get(m).getPid())){
                    EwwVo ewwVo=new EwwVo();

                    ewwVo.setPid(employeelist.get(i).getPId());
                    ewwVo.setName(employeelist.get(i).getName());
                    ewwVo.setYear(philosophylist.get(m).getYear());
                    ewwVo.setQuarter(philosophylist.get(m).getQuarter());
                    ewwVo.setPtotal(philosophylist.get(m).getTotal());
                    ewwVo.setPpoint(philosophylist.get(m).getPoint());


                    philosophyvoList.add(ewwVo);
                }

            }

            for (int n=0;n<abilitylist.size();n++) {
                if (employeelist.get(i).getPId().equals(abilitylist.get(n).getPid())){
                    EwwVo ewwVo=new EwwVo();

                    ewwVo.setPid(employeelist.get(i).getPId());
                    ewwVo.setName(employeelist.get(i).getName());
                    ewwVo.setYear(abilitylist.get(n).getYear());
                    ewwVo.setQuarter(abilitylist.get(n).getQuarter());
                    ewwVo.setAtotal(abilitylist.get(n).getTotal());
                    ewwVo.setApoint(abilitylist.get(n).getPoint());

                    abilityvoList.add(ewwVo);
                }


            }
        }
        return R.ok().put("philosophyvoList",philosophyvoList).put("abilityvoList",abilityvoList);
    }


    @ApiOperation(value = "列表5")
    @GetMapping("list5")
    public R list5(HttpServletRequest request) {


        List<Employee> employeelist = employeeService.list(null);

        List<WorkPhilosophy> philosophylist = workPhilosophyService.list(null);

        List<WorkAbility> abilitylist = workAbilityService.list(null);


        //List<EwwVo> philosophyvoList=new ArrayList<>();
        //List<EwwVo> abilityvoList=new ArrayList<>();
        List<EwwVo> voList=new ArrayList<>();

        for (int i=0;i<employeelist.size();i++){
            for (int m=0;m<philosophylist.size();m++){
                if (employeelist.get(i).getPId().equals(philosophylist.get(m).getPid())){
                    EwwVo ewwVo=new EwwVo();

                    ewwVo.setPid(employeelist.get(i).getPId());
                    ewwVo.setName(employeelist.get(i).getName());
                    ewwVo.setYear(philosophylist.get(m).getYear());
                    ewwVo.setQuarter(philosophylist.get(m).getQuarter());
                    ewwVo.setPtotal(philosophylist.get(m).getTotal());
                    ewwVo.setPpoint(philosophylist.get(m).getPoint());


                    voList.add(ewwVo);
                }

            }

            for (int n=0;n<abilitylist.size();n++) {
                if (employeelist.get(i).getPId().equals(abilitylist.get(n).getPid())){
                    EwwVo ewwVo=new EwwVo();

                    ewwVo.setPid(employeelist.get(i).getPId());
                    ewwVo.setName(employeelist.get(i).getName());
                    ewwVo.setYear(abilitylist.get(n).getYear());
                    ewwVo.setQuarter(abilitylist.get(n).getQuarter());
                    ewwVo.setAtotal(abilitylist.get(n).getTotal());
                    ewwVo.setApoint(abilitylist.get(n).getPoint());

                    voList.add(ewwVo);
                }


            }
        }

        HashMap<String,EwwVo> mapfinalVoList=new HashMap<>();

        for (int n=0;n<voList.size();n++) {
            String key=""+voList.get(n).getPid()+voList.get(n).getName()+voList.get(n).getYear()+voList.get(n).getQuarter();
            EwwVo ewwVo = mapfinalVoList.get(key);
            if (ewwVo == null){
                ewwVo=new EwwVo();
                ewwVo.setPid(voList.get(n).getPid());
                ewwVo.setName(voList.get(n).getName());
                ewwVo.setYear(voList.get(n).getYear());
                ewwVo.setQuarter(voList.get(n).getQuarter());


            }else{
                //ewwVo.setPtotal(philosophylist.get(m).getTotal());
                //ewwVo.setPpoint(philosophylist.get(m).getPoint());
                //ewwVo.setAtotal(abilitylist.get(n).getTotal());
                //ewwVo.setApoint(abilitylist.get(n).getPoint());


                if (voList.get(n).getPtotal() !=null){
                    ewwVo.setPtotal(voList.get(n).getPtotal());
                }
                if (voList.get(n).getPpoint() !=null){
                    ewwVo.setPpoint(voList.get(n).getPpoint());
                }
                if (voList.get(n).getApoint() !=null){
                    ewwVo.setApoint(voList.get(n).getApoint());
                }
                if (voList.get(n).getAtotal() !=null){
                    ewwVo.setAtotal(voList.get(n).getAtotal());
                }
            }
            mapfinalVoList.put(key,ewwVo);
        }







        //for (int m=0;m<philosophyvoList.size();m++) {
        //    EwwVo pewwVo = philosophyvoList.get(m);
        //    for (int n=0;n<abilityvoList.size();n++) {
        //        EwwVo aewwVo = abilityvoList.get(n);
        //
        //        if (pewwVo.getPid().equals(aewwVo.getPid())
        //                && pewwVo.getName().equals(aewwVo.getName())
        //                && pewwVo.getYear().equals(aewwVo.getYear())
        //                && pewwVo.getQuarter().equals(aewwVo.getQuarter())
        //        ) {
        //            EwwVo ewwVo = new EwwVo();
        //            ewwVo.setPid(philosophyvoList.get(m).getPid());
        //            ewwVo.setName(philosophyvoList.get(m).getName());
        //            ewwVo.setYear(abilitylist.get(n).getYear());
        //            ewwVo.setQuarter(abilityvoList.get(n).getQuarter());
        //            ewwVo.setAtotal(abilityvoList.get(n).getTotal());
        //            ewwVo.setApoint(abilityvoList.get(n).getApoint());
        //            ewwVo.setPtotal(philosophyvoList.get(m).getTotal());
        //            ewwVo.setPpoint(philosophyvoList.get(m).getPpoint());
        //            ewwVo.setTotal(philosophyvoList.get(m).getPtotal()
        //                            +abilityvoList.get(n).getApoint()
        //                                    );
        //            finalVoList.add(ewwVo);
        //
        //        }
        //    }
        //
        //
        //}




        //return R.ok().put("data",finalVoList);
        return R.ok().put("data",mapfinalVoList.values());

    }
    */



}

